package com.goldfish666.remote_control.entity.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseAuditWithDistributedId extends BaseKeyWithDistributedId {

    /**
     * 创建时间
     */
    @Column(updatable = false, columnDefinition = "datetime NOT NULL COMMENT '创建时间'")
    @Temporal(TemporalType.TIMESTAMP)
    @CreatedDate
    protected Date createTime;

    /**
     * 更新时间
     */
    @Column(columnDefinition = "datetime NOT NULL COMMENT '更新时间'")
    @Temporal(TemporalType.TIMESTAMP)
    @LastModifiedDate
    protected Date updateTime;

    /**
     * 创建人员
     */
    @Column(updatable = false, columnDefinition = "VARCHAR(50) COMMENT '创建人员'")
    @CreatedBy
    protected String createBy;

    /**
     * 修改人员
     */
    @Column(columnDefinition = "VARCHAR(50) COMMENT '修改人员'")
    @LastModifiedBy
    protected String modifiedBy;
}

